<template>
  <div class="app-container">
      <el-row :gutter="20">
          <el-col :span="8">
              <el-card shadow="hover" class="mgb20" style="height:252px;">
                  <div class="user-info">
                      <img src="../../assets/logo.png" class="user-avator" alt="">
                      <div class="user-info-cont">
                          <div class="user-info-name">{{userName}}</div>
                          <div>{{role}}</div>
                      </div>
                  </div>
                  <div class="user-info-list">
                    操作
                    <span>
                      <el-button type="danger" @click="showModifyPasswd">修改密码</el-button>
                    </span>
                  </div>
              </el-card>
          </el-col>
      </el-row>
      <el-dialog :visible.sync="dialogShow" title="修改密码">
          <el-form style="width:300px;margin-left:50px;">
              <el-form-item label="原密码" required>
                  <el-input v-model="passwd.originPass" type="password"></el-input>
              </el-form-item>
              <el-form-item label="新密码" required>
                  <el-input v-model="passwd.newPass" type="password"></el-input>
              </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogShow = false">取 消</el-button>
            <el-button type="danger" @click="modifyPasswd">确 认</el-button>
            </div>
      </el-dialog>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  data() {
    return {
      userId: this.$store.getters.userId,
      userName: this.$store.getters.userName,
      role: this.$store.getters.role,
      avatar: this.$store.getters.avatar,
      dialogShow: false,
      passwd: {
          originPass: '',
          newPass: ''
      }
    }
  },
  methods: {
      showModifyPasswd() {
          this.dialogShow = true
      },
      async modifyPasswd() {
          if(this.passwd.originPass === '') {
              this.$message.error('请填写原密码')
              return
          }
          if(this.passwd.newPass === '') {
              this.$message.error('请填写新密码')
              return
          }
          if(this.passwd.newPass.length < 8) {
              this.$message.error('新密码长度不能小于8位')
              return
          }
          if(this.passwd.newPass.length > 20) {
              this.$message.error('新密码长度不能大于20位')
              return
          }
          await this.$api.sysuser.modifyPasswd(this.userId, this.passwd)
          this.$message.success('修改成功')
          this.dialogShow = false
      }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el-row {
        margin-bottom: 20px;
    }
    .grid-content {
        display: flex;
        align-items: center;
        height: 100px;
    }
    .grid-cont-right {
        flex: 1;
        text-align: center;
        font-size: 14px;
        color: #999;
    }
    .grid-num {
        font-size: 30px;
        font-weight: bold;
    }
    .grid-con-icon {
        font-size: 50px;
        width: 100px;
        height: 100px;
        text-align: center;
        line-height: 100px;
        color: #fff;
    }
    .grid-con-1 .grid-con-icon {
        background: rgb(45, 140, 240);
    }
    .grid-con-1 .grid-num {
        color: rgb(45, 140, 240);
    }
    .grid-con-2 .grid-con-icon {
        background: rgb(100, 213, 114);
    }
    .grid-con-2 .grid-num {
        color: rgb(45, 140, 240);
    }
    .grid-con-3 .grid-con-icon {
        background: rgb(242, 94, 67);
    }
    .grid-con-3 .grid-num {
        color: rgb(242, 94, 67);
    }
    .user-info {
        display: flex;
        align-items: center;
        padding-bottom: 20px;
        border-bottom: 2px solid #ccc;
        margin-bottom: 20px;
    }
    .user-avator {
        width: 120px;
        height: 120px;
        border-radius: 50%;
    }
    .user-info-cont {
        padding-left: 50px;
        flex: 1;
        font-size: 14px;
        color: #999;
    }
    .user-info-cont div:first-child {
        font-size: 30px;
        color: #222;
    }
    .user-info-list {
        font-size: 14px;
        color: #999;
        line-height: 25px;
    }
    .user-info-list span {
        margin-left: 70px;
    }
    .mgb20 {
        margin-bottom: 20px;
    }
    .todo-item {
        font-size: 14px;
    }
    .todo-item-del {
        text-decoration: line-through;
        color: #999;
    }
    .schart {
        width: 100%;
        height: 300px;
    }
</style>
